package com.experiment.aicommunityback.controller;


import com.experiment.aicommunityback.entity.Goods;
import com.experiment.aicommunityback.entity.Result;
import com.experiment.aicommunityback.entity.dto.GoodsDTO;
import com.experiment.aicommunityback.entity.dto.GoodsTypeFirstChildDTO;
import com.experiment.aicommunityback.mapper.GoodsMapper;
import com.experiment.aicommunityback.service.GoodsService;
import com.experiment.aicommunityback.service.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.List;


@RestController
@RequestMapping("/Goods")
@CrossOrigin()
public class GoodsController {
    @Autowired
    private  GoodsService goodsService;
    @Autowired
    private GoodsTypeService goodsTypeService;
    @Autowired
    private  GoodsMapper goodsMapper;


    public GoodsController(GoodsService goodsService) {
        this.goodsService = goodsService;
    }


    @PostMapping("/selectGoodsTypeList")
    public Result selectGoodsTypeList (){
    return goodsService.selectGoodsTypeList();
    }


    @GetMapping("/selectGoodsStore")
    public Result selectGoodsStore (){
        return goodsTypeService.getGoodsTypeAll();
    }

    @GetMapping("/selectAll")
    public Result selectAll(){
        return goodsService.getAll();
    }

    @PostMapping("/ConditionalQuery")
    public Result Conditional_Query(@RequestBody Map<String, Object> paramMap){
        return goodsService.Conditional_Query(paramMap);
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody List<Integer> arrayData){
        System.out.println(arrayData);
        goodsService.delete(arrayData);
        return goodsService.delete(arrayData);
    }
    @PostMapping("/deleteGoodsType")
    public Result delete_GoodsType(@RequestBody List<Integer> id){
        System.out.println(id);

        return goodsTypeService.deleteGoodsType(id);
    }


    @PostMapping("/addGood")
    public Result addGood(@RequestBody Goods goods){
        System.out.println("+++++++++++++++++++++");
        System.out.println(goods);
        return goodsService.addGood(goods);
    }

    @PostMapping("/addGoodsType")
    public Result addGoodsType(@RequestBody GoodsTypeFirstChildDTO goodstype){
        return goodsService.addGoodsType(goodstype);
    }

//    下面三个是分别更改商品列表中的标签
    @PostMapping("/changeShelves")
    public Result changeShelves(@RequestBody Map<String, Integer> requestBody){
        Integer id = requestBody.get("id");
        return goodsService.changeShelves(id);
    }

    @PostMapping("/changeNewProduct")
    public Result changeNewProduct(@RequestBody Map<String, Integer> requestBody){
        Integer id = requestBody.get("id");
        return goodsService.changeNewProduct(id);
    }

    @PostMapping("/changeRecommend")
    public Result changeRecommend(@RequestBody Map<String, Integer> requestBody){
        Integer id = requestBody.get("id");
        return goodsService.changeRecommend(id);
    }

    @GetMapping("/getSecondTypeGoodsList")
    public Result getSecondTypeGoodsList(){
        return goodsService.getSecondTypeGoodsList();
    }

    @PostMapping("/updateGood")
    public Result updateGood(@RequestBody Goods good){

        System.out.println(good.getTypeId());
        return goodsService.updateGood(good);
    }

    @GetMapping("/getAllFirstGoodsType")
    public Result getAllFirstGoodsType(){
        return goodsService.getAllFirstGoodsType();
    }

    @PostMapping("/updateGoodsType")
    public Result updateGoodsType(@RequestBody GoodsTypeFirstChildDTO goodstype){
        return goodsService.updateGoodsType(goodstype);
    }
}
